#include "hypnotoad.h"

hypnotoad::hypnotoad(QGraphicsView *parent) : QGraphicsView(parent)
{
    ajastin = new QTimer(this);
    ajastin->start(15);

    media = new Phonon::MediaObject(this);
    aani = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(media, aani);

    media->setCurrentSource(Phonon::MediaSource(QString("hypnotoad.mp3")));

    scene = new QGraphicsScene();
    setScene(scene);

    this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    hypno = scene->addPixmap(QPixmap(":/hypnotoad.png"));
    hypno->setPos(0, 60);

    connect(ajastin, SIGNAL(timeout()), this, SLOT(pyorita()));
    connect(media, SIGNAL(finished()), this, SLOT(soita()));

    soita();
}

void hypnotoad::soita()
{
    media->play();
}

void hypnotoad::pyorita()
{
    hypno->setRotation(hypno->rotation()+5);
}

void hypnotoad::sulje()
{
    close();
}

hypnotoad::~hypnotoad()
{
    media->stop();
    media->deleteLater();
    ajastin->deleteLater();
    scene->deleteLater();
}
